package repository

import (
	"niu-video/app/model"
	"niu-video/pkg/db"
)

var CommentRepository = newCommentRepository()

func newCommentRepository() *commentRepository {
	return &commentRepository{}
}

type commentRepository struct {
	baseRepository
}

func (v *commentRepository) GetVideoCommentList(videoId int64) (comments []model.Comment) {
	db.DB.Where("video_id = ? AND parent_id = 0", videoId).Order("comment_id desc").Find(&comments)
	return
}

func (v *commentRepository) Create(comment *model.Comment) (err error) {
	err = db.DB.Create(comment).Error
	return err
}

func (v *commentRepository) GetChildren(parentId int64) (comments []model.Comment) {
	db.DB.Where("parent_id = ?", parentId).Find(&comments)
	return
}

func (v *commentRepository) Delete(commentId int64) {
	db.DB.Where("comment_id = ?", commentId).Delete(&model.Comment{})
	return
}
